package ge.telasi.tasks.model.validation;

import ge.telasi.tasks.LocaleManager;
import ge.telasi.tasks.TaskException;

/**
 * Use for empty value validation.
 *
 * @author dimitri
 */
public class EmptyFieldValidator extends Validator {

    public void validate(String name, String value) {
        boolean empty = value == null || value.trim().length() == 0;
        if (empty) {
            LocaleManager lm = getLocaleManager();
            String humanName = lm.getMessage(name);
            String msg = lm.getMessage("EmptyFieldValidator.text", humanName);
            throw new TaskException(msg, name);
        }
    }

    public void validate(String name, Object value) {
        boolean empty = value == null;
        if (empty) {
            LocaleManager lm = getLocaleManager();
            String humanName = lm.getMessage(name);
            String msg = lm.getMessage("EmptyFieldValidator.object", humanName);
            throw new TaskException(msg, name);
        }
    }

}
